package 我的Java学习_算法基础.day_04;

public class _062_Z形打印二位数组 {
    public static void main(String[] args) {
        int[][] a = {
                {1  ,2  ,3  ,4},
                {5  ,6  ,7  ,8},
                {9  ,10 ,11 ,12}
        };
        print(a);
    }
    private static void print(int[][] array){
        int r = 0,row = array.length;
        int c = 0,column = array[0].length;
        boolean lToRight = true;
        while(r<row&&c<column){
            System.out.print(array[r][c]+" ");
            if(lToRight) {

                if (r == 0 && c < column - 1) {
                    lToRight = !lToRight;
                    c++;
                    continue;
                } else if (r > 0 && c == column - 1) {
                    lToRight = !lToRight;
                    r++;
                    continue;
                } else {
                    r--;
                    c++;
                }
            }else{
                if(c==0&&r<row-1){
                    lToRight=!lToRight;
                    r++;
                    continue;
                }else if(r==row-1){
                    lToRight=!lToRight;
                    c++;
                    continue;
                }else{
                    r++;
                    c--;
                }
            }

        }
    }
}
